<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>cacti 安装 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>cacti 安装</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Cacti/">Cacti</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：cacti 需要 apache 和 php 的支持，在这里使用 yum 安装 lamp 环境。</p>
<h2 id="1-安装-epel"><a href="#1-安装-epel" class="headerlink" title="1.安装 epel"></a>1.安装 epel</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># yum install -y epel-release</span></div></pre></td></tr></table></figure>
<h2 id="2-安装-lamp"><a href="#2-安装-lamp" class="headerlink" title="2.安装 lamp"></a>2.安装 lamp</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># yum install -y httpd php php-mysql mysql mysql-server mysql-devel php-gd libjpeg libjpeg-devel libpng libpng-devel</span></div></pre></td></tr></table></figure>
<h2 id="3-安装-cacti"><a href="#3-安装-cacti" class="headerlink" title="3.安装 cacti"></a>3.安装 cacti</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]# yum install -y cacti net-snmp net-snmp-utils rrdtool</div></pre></td></tr></table></figure>
<h2 id="4-启动服务"><a href="#4-启动服务" class="headerlink" title="4.启动服务"></a>4.启动服务</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># /etc/init.d/httpd start</span></div><div class="line">[root@cacti ~]<span class="comment"># /etc/init.d/mysqld start</span></div><div class="line">[root@cacti ~]<span class="comment"># /etc/init.d/snmpd start</span></div></pre></td></tr></table></figure>
<h2 id="5-编辑-httpd-conf"><a href="#5-编辑-httpd-conf" class="headerlink" title="5.编辑 httpd.conf"></a>5.编辑 httpd.conf</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># vim /etc/httpd/conf.d/cacti.conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;把 “Deny from all” 改为 “Allow from all”</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># /etc/init.d/httpd restart</span></div></pre></td></tr></table></figure>
<h2 id="6-导入数据创建-cacti-库"><a href="#6-导入数据创建-cacti-库" class="headerlink" title="6.导入数据创建 cacti 库"></a>6.导入数据创建 cacti 库</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># mysql -uroot -e "create database cacti"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建 cacti 用户</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># mysql -uroot -e "grant all on cacti.* to 'cacti'@'127.0.0.1' identified by 'cacti';"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;导入 sql 文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># mysql -uroot cacti &lt; /usr/share/doc/cacti-1.0.4/cacti.sql</span></div></pre></td></tr></table></figure>
<h2 id="7-编辑-cacti-配置文件"><a href="#7-编辑-cacti-配置文件" class="headerlink" title="7.编辑 cacti 配置文件"></a>7.编辑 cacti 配置文件</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># vim /usr/share/cacti/include/config.php</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;更改如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="variable">$database_type</span> = <span class="string">"mysql"</span>;</div><div class="line"><span class="variable">$database_default</span> = <span class="string">"cacti"</span>;</div><div class="line"><span class="variable">$database_name</span> = <span class="string">"cacti"</span>;</div><div class="line"><span class="variable">$database_hostname</span> = <span class="string">"127.0.0.1"</span>;</div><div class="line"><span class="variable">$database_username</span> = <span class="string">"cacti"</span>;</div><div class="line"><span class="variable">$database_password</span> = <span class="string">"cacti"</span>;</div><div class="line"><span class="variable">$database_port</span> = <span class="string">"3306"</span>;</div><div class="line"><span class="variable">$database_ssl</span> = <span class="literal">false</span>;</div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/01.png?raw=true" alt="01"><figcaption class="figure__caption">01</figcaption></figure></p>
<h2 id="8-web-访问-cacti-并安装"><a href="#8-web-访问-cacti-并安装" class="headerlink" title="8.web 访问 cacti 并安装"></a>8.web 访问 cacti 并安装</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;浏览器访问  <a href="http://ip/cacti/" target="_blank" rel="external">http://ip/cacti/</a></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/02.png?raw=true" alt="02"><figcaption class="figure__caption">02</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;出现错误</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/03.png?raw=true" alt="03"><figcaption class="figure__caption">03</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;执行命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># set time_zone = '+8:00';</span></div><div class="line">[root@cacti ~]<span class="comment"># mysql -u root mysql -p -e "GRANT SELECT ON mysql.time_zone_name TO cacti@localhost IDENTIFIED BY 'cacti';"</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;继续报错</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/04.png?raw=true" alt="04"><figcaption class="figure__caption">04</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># vim /etc/php.ini</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/05.png?raw=true" alt="05"><figcaption class="figure__caption">05</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改为</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/06.png?raw=true" alt="06"><figcaption class="figure__caption">06</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;执行命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root mysql -p</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决问题</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/07.png?raw=true" alt="07"><figcaption class="figure__caption">07</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;报错</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/08.png?raw=true" alt="08"><figcaption class="figure__caption">08</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;首先要升级 mysql 版本</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;更新 yum 源</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># yum update</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加 mysql5.6 yum 源</p>
<ul>
<li>centos6</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm</span></div></pre></td></tr></table></figure>
<ul>
<li>centos7</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后 yum 安装 mysql 就是 5.6 版本了</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;版本更换后</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/09.png?raw=true" alt="09"><figcaption class="figure__caption">09</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;根据提示 修改 /etc/my.cnf 配置</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># vim /etc/my.cnf</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/10.png?raw=true" alt="10"><figcaption class="figure__caption">10</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重启 mysql 服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># /etc/init.d/mysqld restart</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;刷新网页</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/11.png?raw=true" alt="11"><figcaption class="figure__caption">11</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;报错</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/12.png?raw=true" alt="12"><figcaption class="figure__caption">12</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;安装php-posix</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># yum -y install php-process</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;重启</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/13.png?raw=true" alt="13"><figcaption class="figure__caption">13</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;点击下一步</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/14.png?raw=true" alt="14"><figcaption class="figure__caption">14</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;选择默认  new primary server 下一步</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/15.png?raw=true" alt="15"><figcaption class="figure__caption">15</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下一步</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/16.png?raw=true" alt="16"><figcaption class="figure__caption">16</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;下一步</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/17.png?raw=true" alt="17"><figcaption class="figure__caption">17</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;选择模版，并点完成</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;登录，这里初始用户名和密码都为 admin</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/18.png?raw=true" alt="18"><figcaption class="figure__caption">18</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;初次登录强制要求更改密码。注：新密码长度必须 8 位以上，必须包含大小写字母、特殊符号、数字。</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/19.png?raw=true" alt="19"><figcaption class="figure__caption">19</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后进入监控页面</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/20.png?raw=true" alt="20"><figcaption class="figure__caption">20</figcaption></figure></p>
<h2 id="9-执行-poller-php-，生成图形，加入任务计划"><a href="#9-执行-poller-php-，生成图形，加入任务计划" class="headerlink" title="9.执行 poller.php ，生成图形，加入任务计划"></a>9.执行 poller.php ，生成图形，加入任务计划</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;登录有选择图形是没有显示的</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/21.png?raw=true" alt="21"><figcaption class="figure__caption">21</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;执行脚本</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># /usr/bin/php /usr/share/cacti/poller.php</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;执行脚本时提示很多 warning</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># vim /etc/php.ini</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/22.png?raw=true" alt="22"><figcaption class="figure__caption">22</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改为</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/23.png?raw=true" alt="23"><figcaption class="figure__caption">23</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样再次执行就不会提示 warning 了</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/24.png?raw=true" alt="24"><figcaption class="figure__caption">24</figcaption></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;添加 cron 任务计划</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@cacti ~]<span class="comment"># crontab -e</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;增加</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">*/5 * * * * /usr/bin/php/usr/share/cacti/poller.php</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;浏览器出现图形</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/cacti%E5%AE%89%E8%A3%85/25.png?raw=true" alt="25"><figcaption class="figure__caption">25</figcaption></figure></p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Cacti/1. cacti 安装/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
